package com.mrd.spring.listener;

import com.mrd.gtimpframe.repository.DeclarationMapper;
import com.mrd.redis.JedisClientClusterImpl;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Created by dusy on 2017/8/30.
 */
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        DeclarationMapper declarationMapper = contextRefreshedEvent.getApplicationContext().getBean(DeclarationMapper.class);
        List<String> ids = declarationMapper.selectLocked();
        if (ids != null) {
            JedisClientClusterImpl jedisClientCluster = contextRefreshedEvent.getApplicationContext().getBean(JedisClientClusterImpl.class);
            for (String id : ids) {
                jedisClientCluster.set("lock_decla_" + id, String.class, 30L, TimeUnit.DAYS);
            }
        }
    }
}


